<template>
	<view>
		<view class="add">
			<view :class="{'active':isActive==1}" @click="chenked(1)" style="width: 50%; border:1px solid #ddd">
				<text class="wenzi">补货</text>
			</view>
			<view :class="{'active':isActive==2}" @click="chenked(2)" style=" width: 50%; border: 1px solid #ddd;">
				<text class="wenzi">订单</text>
			</view>
		</view>
		<view class="buh" v-if="isActive==1">
			<view class="goods">
				<uni-search-bar class="uni-mt-10" radius="5" @confirm="search" placeholder="自动显示隐藏" clearButton="auto"
					cancelButton="none"/>
				<scroll-view scroll-y="true" style="height: 500px;">
					<view v-for="(goods,index) in goodsList" :key="index">
						<uni-card :is-shadow="false">
							<view class="cardi">
								<image :src="goods.imgeUrl" style=" width: 50px;height: 50px;"></image>
								<view style="margin-left: 10px;"><text style="font-size: 20px;">{{goods.goodsName}}
								</text><text style="margin-left: 10px;">{{goods.goodsInprice/100}}¥</text>
								<uni-number-box  :value="goods.number" :current="goods.number"  @change="changeValue(goods,$event)"/>
								</view>
								<!-- <view></view> -->
								</view>
						</uni-card>
					</view>
				</scroll-view>
			<button @click="jiesuan()">结算（{{sumPrice/100}}）</button>
				<view style="width: 100%;height: 30px;" class="jiesuan">
					<!-- <text style="font-size: 20px;">总价：{{123.6}}</text>
					<navigator url="../ddqueren/ddqueren">
						<button type="primary">结算</button>
					</navigator> -->
					<view class="end">
						<view class="end-left">
					
							<view>
								总计：<text style="color: #f00;font-weight: bold;">￥ {{123.7}}</text>
							</view>
						</view>
						<view class="end-right" @click="jiesuan()">
							结算({{sumPrice}})
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="dingdan" v-if="isActive==2">
			<view v-for="order in orderlist">
					<uni-card :title=order.order :extra=order.staet @click="clickCard()">
						<text class="uni-body">
							供货点名称：{{order.ghName}}
							日期：{{order.createData}}
							金额：{{order.price}}
						</text>
					</uni-card>
			</view>
		</view>
	</view>
</template>

<script>
	import{request} from'@/network/http.js'
import { forEach } from 'luch-request/src/lib/utils'
	export default {
		data() {
			return {
				sumPrice:0,
				isActive: 1,
				orderlist: [],
				goodsList:[],
				shopcar:[],
			}

		},
		onShow(){
			
			this.token=uni.getStorageSync("refreshToken")
			request({
				url:`admin/ssmgoods/list2`,
				method:'GET',
			}).then(res=>{
				this.goodsList=res.data.list
			})
			request({
			url:`driver/ssmsj/getorder/${this.token}`,
			method:'get',
			data:{
			}
		}).then(res=>{
			this.orderlist=res.data.orderList
		})
		},
	
		methods: {
			search(res){
				request({
					url:'admin/ssmgoods/list2',
					method:'get',
					data:{
						key:res
					}
				})
			},
			changeValue(goods,value){
				
				let sum=0
				let i=0
				goods.number=value
				for(i=0;i<this.goodsList.length;i++){
					// console.log(this.goodsList[i])
				sum +=	this.goodsList[i].number*this.goodsList[i].goodsInprice
				}
				console.log(sum)
				this.sumPrice=sum
				// this.shopcar.push(goods)
			},
			chenked(type) {
				this.isActive = type
			},
			clickCard(){
				uni.navigateTo({
					url:"/pages/ddxiangqing/ddxiangqing"
				})
			},
			jiesuan(){
				let i=0
				for(i=0;i<this.goodsList.length;i++){
					if(this.goodsList[i].number!=0){
						this.shopcar.push(this.goodsList[i])
					}
					
					
				}
				request({
					url:"supplier/ssmsuorder/save",
					method:'POST',
					data:{
						refreshToken:uni.getStorageSync("refreshToken"),
						shopcar:this.shopcar
					}
				}).then(res=>{
					console.log(res)
					uni.navigateTo({
						url:`/pages/ddqueren/ddqueren?orderid=${res.data.orderId}`
					})
				})
			
			}

		}
	}
</script>

<style lang="scss">
	.cardi{
		display: flex;
		flex-direction: row;
		justify-content: space-around;
	}
	.add {
		text-align: center;
		line-height: 35px;
		display: table-cell;
		vertical-align: middle;
		font-size: 30px;
		width: 100%;
		height: 50px;
		display: flex;
		flex-direction: row;
		justify-content: space-around;
	}

	.active {
		color: #4ac366;
	}

	.jiesuan {
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		margin-bottom: 60px;

	}

	.end {
		width: 100%;
		height: 80rpx;
		background-color: #fff;
		position: fixed;
		bottom: 0rpx;
		left: 0;
		display: flex;
		align-items: center;

		&-left {
			width: 70%;
			display: flex;
			justify-content: space-between;
			padding: 0 30rpx;

			.end-flex {
				display: flex;
				align-items: center;
			}
		}

		&-right {
			width: 30%;
			line-height: 80rpx;
			background-color: #F44545;
			text-align: center;
			color: #fff;
		}
	}
</style>
